<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字符的位置</title>
</head>
<body>
<script>
    var stringValue = "good good study,day day up,good good girl";
    var index;
    var loaction = new Array();

    console.log("查出所有ood的位置");

    index = stringValue.indexOf("ood");
    while(index>-1){
        loaction.push(index);
        index = stringValue.indexOf("ood",index+1);
        console.log(index);
    }

    console.log(loaction);
//当查不到时返回-1，这样就不符合while条件了，就终止循环了
</script>

</body>
</html>